package com.phb.puhuibao.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.idp.pub.dao.IBaseDao;
import com.idp.pub.dao.IPagerDao;
import com.idp.pub.service.impl.DefaultBaseService;
import com.idp.sysmgr.user.entity.User;
import com.phb.puhuibao.entity.UserMessage;
import com.phb.puhuibao.entity.UserSession;
import com.phb.puhuibao.service.UserMessageService;

@Transactional
@Service("userMessageService")
public class UserMessageServiceImpl extends DefaultBaseService<UserMessage, String>   implements UserMessageService{
	@Resource(name = "userMessageDao")
	public void setBaseDao(IBaseDao<UserMessage, String> baseDao) {
		super.setBaseDao(baseDao);
	}

	@Resource(name = "userMessageDao")
	public void setPagerDao(IPagerDao<UserMessage> pagerDao) {
		super.setPagerDao(pagerDao);
	}
	@javax.annotation.Resource(name = "jdbcTemplate")
	private JdbcTemplate jdbcTemplate;
	@Override
	public List<Map<String ,Object>> getJobMes(String type , String userId ,String pageno) {
		String sql = "select a.job_id ,a.create_time ,a.content ,b.job_title ,c.status from phb_muser_message a LEFT JOIN phb_muser_job_release b on a.job_id=b.job_id left join phb_number c on b.job_id=c.job_id where a.type="+type+" and a.user_id="+userId +"limit "+Integer.parseInt(pageno)*5 +" ,"+(Integer.parseInt(pageno)+1)*5;
		List<Map<String ,Object>> list = this.jdbcTemplate.queryForList(sql);
		List<Map<String ,Object>> jobs = this.jdbcTemplate.queryForList(sql);
		for (Map<String, Object> map : list) {
			Map<String, Object> job =new HashMap<String, Object>();
			job.put("jobId", map.get("job_id"));
			job.put("createTime", map.get("create_time"));
			job.put("content", map.get("content"));
			job.put("jobTitle", map.get("job_title"));
			job.put("jobStatus", map.get("status"));
			jobs.add(job);			
		}
		return jobs;
	}
}
